package com.robusta.app.domain.spreadsheet;

import java.util.Collection;

/**
 * Generic spreadsheet model
 * Every row of the sheet is captured in a Model.
 * Ever column of the row is captured in a Field and collected in the Model.
 */
public interface Model {
    /**
     * Adds the field into the model after doing the following checking
     *  that no other field exists with same field name and
     *  if field being added is a key field, there is no prior key field
     *  known to the model.
     * @param field Field
     * @throws IllegalArgumentException when preconditions fail.
     */
    void add(Field field);
    /**
     * Match field by name and return contained value.
     * null if there is no matching field.
     * @param fieldName Field name to be matched
     * @return field value or null
     */
    String getFieldValue(String fieldName);

    /**
     * Match field by name and return.
     * null if there is no matching field.
     * @param fieldName Field name to be matched
     * @return field or null
     */
    Field getField(String fieldName);

    /**
     * All contained fields.
     * @return Collection of fields.
     */
    Collection<? extends Field> allFields();

    /**
     * Of the contained fields, one ia marked key field.
     * Returns value from the key field or null if key field
     * is not defined.
     * @return Key Field value or null
     * @see Model.Field#isKey()
     */
    String getKeyFieldValue();

    public interface Field {
        String getFieldName();
        String getFieldValue();
        boolean isKey();
    }
}
